<template>
  <div class="custom-layout">
    <!-- 引入导航栏 -->
    <custom-navbar/>

    <div class="main-content">
      <div class="app-container">
        <el-row :gutter="20">
          <el-col :span="6" :xs="24">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>个人信息</span>
              </div>
              <div>
                <div class="text-center">
                  <userAvatar />
                </div>
                <ul class="list-group list-group-striped">
                  <li class="list-group-item">
                    <svg-icon icon-class="user" />用户名称
                    <div class="pull-right">{{ user.userName }}</div>
                  </li>
                  <li class="list-group-item">
                    <svg-icon icon-class="phone" />手机号码
                    <div class="pull-right">{{ user.phonenumber }}</div>
                  </li>
                  <li class="list-group-item">
                    <svg-icon icon-class="email" />用户邮箱
                    <div class="pull-right">{{ user.email }}</div>
                  </li>
                  <li class="list-group-item">
                    <svg-icon icon-class="tree" />所属部门
                    <div class="pull-right" v-if="user.dept">{{ user.dept.deptName }} / {{ postGroup }}</div>
                  </li>
                  <li class="list-group-item">
                    <svg-icon icon-class="peoples" />所属角色
                    <div class="pull-right">{{ roleGroup }}</div>
                  </li>
                  <li class="list-group-item">
                    <svg-icon icon-class="date" />创建日期
                    <div class="pull-right">{{ user.createTime }}</div>
                  </li>
                </ul>
              </div>
            </el-card>
          </el-col>
          <el-col :span="18" :xs="24">
            <el-card>
              <div slot="header" class="clearfix">
                <span>基本资料</span>
              </div>
              <el-tabs v-model="activeTab">
                <el-tab-pane label="基本资料" name="userinfo">
                  <userInfo :user="user" />
                </el-tab-pane>
                <el-tab-pane label="修改密码" name="resetPwd">
                  <resetPwd />
                </el-tab-pane>
              </el-tabs>
            </el-card>
          </el-col>
        </el-row>
      </div>
    </div>
  </div>

</template>

<script>
import userAvatar from "./userAvatar"
import userInfo from "./userInfo"
import resetPwd from "./resetPwd"
import { getUserProfile } from "@/api/system/user"
import CustomNavbar from "@/components/CustomNavbar";

export default {
  name: "Profile",
  components: {CustomNavbar, userAvatar, userInfo, resetPwd },
  data() {
    return {
      user: {},
      roleGroup: {},
      postGroup: {},
      activeTab: "userinfo"
    }
  },
  created() {
    this.getUser()
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data
        this.roleGroup = response.roleGroup
        this.postGroup = response.postGroup
      })
    }
  }
}
</script>
<style >
/* 使用与首页一致的配色方案 */
.main-content {
  position: absolute;
  top: 0; /* 强制贴顶 */
  left: 260px; /* 等于导航栏宽度 */
  width: calc(100% - 260px);
  height: 100vh;
  overflow-y: auto;

  background: white;
  z-index: 10; /* 确保在导航栏上方 */
}
:root {
  --primary-100: #8B5FBF;
  --primary-200: #61398F;
  --primary-300: #FFFFFF;
  --accent-100: #D6C6E1;
  --accent-200: #9A73B5;
  --text-100: #4A4A4A;
  --text-200: #878787;
  --bg-100: #F5F3F7;
  --bg-200: #E9E4ED;
  --bg-300: #FFFFFF;
}

/* 表单容器样式 */
.el-form {
  background: var(--bg-300);
  padding: 25px;
  border-radius: 12px;
  box-shadow: 0 4px 12px rgba(139, 95, 191, 0.08);
  border: 1px solid var(--bg-200);
}

/* 表单标题样式 */
.el-form-item__label {
  color: var(--primary-200);
  font-weight: 600;
  font-size: 14px;
  padding-right: 12px;
}

/* 输入框样式 */
.el-input__inner, .el-date-editor.el-input__inner {
  height: 40px;
  line-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--bg-200);
  background-color: var(--bg-300);
  transition: all 0.3s ease;
  color: var(--text-100);
}

.el-input__inner:focus, .el-date-editor.el-input__inner:focus {
  border-color: var(--primary-100);
  box-shadow: 0 0 0 2px rgba(139, 95, 191, 0.2);
}

/* 日期选择器样式 */
.el-date-editor .el-input__prefix,
.el-date-editor .el-input__suffix {
  color: var(--primary-100);
}

/* 按钮样式 */
.el-button {
  border-radius: 8px;
  padding: 10px 20px;
  font-weight: 500;
  transition: all 0.3s ease;
}

.el-button--primary {
  background: linear-gradient(135deg, var(--primary-100), var(--primary-200));
  border: none;
  color: var(--primary-300);
}

.el-button--primary:hover {
  background: linear-gradient(135deg, var(--primary-200), var(--primary-100));
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(139, 95, 191, 0.3);
}

.el-button--default {
  border: 1px solid var(--primary-100);
  color: var(--primary-100);
  background: var(--bg-300);
}

.el-button--default:hover {
  background: var(--primary-100);
  color: var(--primary-300);
}

/* 表单项间距 */
.el-form-item {
  margin-bottom: 22px;
}

/* 搜索表单特殊样式 */
.el-form--inline .el-form-item {
  margin-right: 15px;
  margin-bottom: 15px;
}

/* 表格操作按钮样式 */
.el-button--text {
  color: var(--primary-100);
  font-weight: 500;
}

.el-button--text:hover {
  color: var(--primary-200);
}

/* 对话框表单样式 */
.el-dialog__body .el-form {
  padding: 10px 20px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .el-form--inline .el-form-item {
    display: block;
    margin-right: 0;
    width: 100%;
  }

  .el-form-item__content {
    width: 100%;
  }

  .el-input, .el-date-editor {
    width: 100% !important;
  }
}

/* 添加动画效果 */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.el-form-item {
  animation: fadeIn 0.3s ease forwards;
}

/* 为不同表单项添加延迟动画 */
.el-form-item:nth-child(1) { animation-delay: 0.1s; }
.el-form-item:nth-child(2) { animation-delay: 0.2s; }
.el-form-item:nth-child(3) { animation-delay: 0.3s; }
.el-form-item:nth-child(4) { animation-delay: 0.4s; }
.el-form-item:nth-child(5) { animation-delay: 0.5s; }
</style>
